<?php
 
include_once("./configure/configure.php");						//--> global var
include_once("./admin/tools/smarty/libs/Smarty.class.php");		//--> out template

include_once("impl/ContentImpl.php");
include_once("impl/ImageImpl.php");
include_once("impl/CategoryImpl.php");
include_once("impl/TagImpl.php");


include_once("includeSmarty.php");


$contentId 	= $_GET['contentId'];
$imgId 		= $_GET['imgId'];

if(empty($contentId))
	$contentId = $_POST['contentId'];

if(empty($imgId))
	$imgId = $_POST['imgId'];
	
if(empty($contentId) || empty($imgId)){
	$location = HOME_URL_HTTP;
	
	header("Location: $location");
	exit;
}


$imgImpl 	= new ImageImpl(DB_TAG_MM);
$oContImpl 	= new ContentImpl(DB_TAG_MM);
$oCatImpl 	= new CategoryImpl(DB_TAG_MM);
$tagImpl	= new TagImpl(DB_TAG_MM);



$oImg 	= $imgImpl->getById($imgId);
if(!is_object($oImg)){
	$location = HOME_URL_HTTP;
	
	header("Location: $location");
	exit;
}


$arrImgIds 	= $oContImpl->getImageIds($contentId);

$preImgId	= $oContImpl->getPreId($arrImgIds, $imgId);
$nextImgId	= $oContImpl->getNextId($arrImgIds, $imgId);

if($preImgId > 0)
	$oPreImg = $imgImpl->getById($preImgId);
else
	$oPreImg = new ImageDto();
	
if($nextImgId > 0)
	$oNextImg = $imgImpl->getById($nextImgId);
else
	$oNextImg = new ImageDto();	 


//get related image
$oRelatedImages	= $oContImpl->getRelatedImagePage($contentId, 1, 10);
		
if(count($oRelatedImages) < 6){
	$oPopularImages	= $oContImpl->getPopularImages();
	
	$oRelatedImages = array_merge($oRelatedImages, $oPopularImages);
}


// get all images for this content
$oAllImages = $oContImpl->getAllImages($contentId);
$oImages = array();
foreach($oAllImages as $oImgTmp){
	if($oImgTmp->id != $imgId)
		$oImages[] = $oImgTmp;
}

$oCats 	= $oCatImpl->getLeaf();
$oTags	= $tagImpl->getTags();


$imgImpl->onClick($imgId);


$smarty->assign('oPreImg', $oPreImg);
$smarty->assign('oNextImg', $oNextImg);

$smarty->assign('oImg', $oImg);
$smarty->assign('contentId', $contentId);

$smarty->assign('oImages', $oImages);
$smarty->assign('oRelatedImages', $oRelatedImages);

$smarty->assign('oCats', $oCats);
$smarty->assign('oTags', $oTags);

$smarty->assign('HOME_URL', HOME_URL);
$smarty->assign('HOME_URL_HTTP', HOME_URL_HTTP);
$smarty->assign('DEBUG', DEBUG);


$smarty->display('contentDetails.html');
?>
